<!--стилі віконце-вказівник-->
<style>
    #quotePointer{
        position: absolute;
        display: none;
    }
    
    .chat-bubble {
        background-color: wheat;
        border:2px solid #666666;
        font-size:14px;
        line-height:1.3em;
        margin:10px auto;
        padding:10px;
        position:relative;
        text-align:center;
        width:120px;
        -moz-border-radius:10px;
        -webkit-border-radius:10px;
        -moz-box-shadow:0 0 5px #888888;
        -webkit-box-shadow:0 0 5px #888888;
    }
    
    .chat-bubble a {
        color: mediumorchid;
    }

    .chat-bubble-arrow-border {
        border-color: #666666 transparent transparent transparent;
        border-style: solid;
        border-width: 10px;
        height:0;
        width:0;
        position:absolute;
        bottom:-20px;
        left:30px;
    }

    .chat-bubble-arrow {
        border-color: wheat transparent transparent transparent;
        border-style: solid;
        border-width: 10px;
        height:0;
        width:0;
        position:absolute;
        bottom:-19px;
        left:30px;
    }
</style>
<?php 
    $params = array('catId'=>$cat['catId'], 'partnerUrl'=>$partner['url']);
    $page = $pagination->getCurrentPage() ? $pagination->getCurrentPage() + 1 : '';
    $themeUrl = Yii::app()->createAbsoluteUrl('partner/forum/theme', array('id'=>$theme['themeId'], 'catId'=>$cat['catId'], 'partnerUrl'=>$partner['url']));
?>    
<script>
    var userIsGuest = Number('<?php echo Yii::app()->user->isGuest; ?>'.replace(/\D+/g,""));
    var page = '';
    var type = 'forum_topic';
    var forumUrl = '<?php echo Yii::app()->createAbsoluteUrl('partner/forum/index', $params); ?>';
    var themeUrl = '<?php echo !empty($page) ? $themeUrl.'?page='.$page : $themeUrl; ?>';
</script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/forum.js"></script>
<script type="text/javascript">
    tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        skin : "default",
        width : 562,
        height : 210,
        invalid_elements: "img, script, h1, h2, h3, h4, h5, h6, h7, font, iframe, object",
       
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_toolbar_location : false,
        theme_advanced_toolbar_align : false,
        theme_advanced_statusbar_location : false,
        theme_advanced_resizing : false,
        theme_advanced_path : false,
        convert_urls : false,
        relative_urls : false
    });
</script>
<?php Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl.'/js/scrollTo.js'); ?>
<?php $this->renderPartial('//partials/partnerMenu', array('partner'=>$partner, 'advertCode'=>$advertCode, 'cat'=>$cat, 'errorModel'=>$errorModel, 'userIsWork'=>$userIsWork, 'relProfiles'=>$relProfiles, 'subCats'=>$subCats, 'curent'=>'forum','show_tabs'=>1));?> 
<div class="padding4020">
<div class="forum_desclame">Обсуждается все что связанно с партнеркой "<?php echo $partner['name'];?>" и категорией "<?php echo $cat['name'];?>". 
Вы можете задать вопрос сразу предствателю сразу партнерки, или кому еще. Что в голову взбредет короче.</div>    

<div class="pull-right showForm">Создать тему</div>

<div class="newThemeForm" style="<?php echo $themeModel->hasErrors() ? 'display:block;' : 'display:none;'; ?>">
<div class="forum_form_cut"></div>
<div class=" comment_form" >
    
    <?php echo CHtml::errorSummary($themeModel, 'Пожалуйста исправьте следующие ошибки:'); ?>
    <?php echo CHtml::beginForm(); ?>
    <span>
        <span class="pull-right close_form"></span>
    </span>
    
      <?php $userId = !Yii::app()->user->isGuest ? Yii::app()->user->getId() : 'null' ; ?>
    <div class="pull-left mar-top10">
      <?php echo CHtml::activeLabel($themeModel, 'title',array('style'=>'color:#898989;fomt-size:12px;')); ?>
        <?php echo CHtml::activeTextField($themeModel, 'title', array('class'=>'forum_new_teme', 'style'=>'margin-bottom:15px;')); ?>
        
        <?php echo CHtml::activeLabel($themeModel, 'text',array('style'=>'color:#898989;fomt-size:12px;')); ?>
        <?php echo CHtml::activeTextArea($themeModel, 'text', array('class'=>'text_area_comm', 'id'=>'theme','style'=>'width:600px;')); ?>
    </div>    
        
    <div class="pull-left" style="margin-left: 33px;margin-top: 33px;">
      
         <?php if($partner['delegate1'] + $partner['delegate2'] && $userId != $partner['delegate1'] && $userId != $partner['delegate2']) : ?>
          
                <?php echo CHtml::activeCheckBox($themeModel, 'isSupport',array('id'=>'is_off_comment')); ?> <label for="is_off_comment"><span style="font-size: 12px;line-height: 12px;">Отправить как официальный<br/> вопрос представителю<br/> партнерки.</label>
        <br/>
        <div class="ct_znak"></div>
        <div style="color:#898989;font-size:12px;margin-left: 20px;">Сообщение буддет помечено<br/> вот таким четким значком и <br/>представителю отправится<br/> уведомление.</div>
           
        <?php endif; ?>
      </div>  
                    
  <div class="clearfix"></div> 
  
   <div class="pull-left mar-top20">
     <div id="fileUpload">
            <?php $this->widget('xupload.XUpload', array(
                'url' => Yii::app()->createUrl("partner/forum/upload"),
                'model' => new XUploadForm, 
                        'attribute' => 'file',
                        'showForm' => false,    
                        'multiple' => true,
                        'options' => array( 
                            'autoUpload' => true, 
                            'maxNumberOfFiles' => 5, 
                            'maxFileSize' => 2000000,
                            'acceptFileTypes' => "js:/(\.|\/)(jpe?g|png|gif)$/i",
                        ),
                        'downloadView' => 'forumDownload',
                        'htmlOptions' => array('id' => 'fileUpload'),
            )); ?>
     </div>
  </div>
   <div class="clearfix"></div> 
    <div class="pull-left">
        <?php echo CHtml::submitButton('Создать',array('class'=>'addpst')); ?> 
    </div>
        <?php echo CHtml::activeHiddenField($themeModel, 'partnerId', array('value'=>$partner['partnerid'], 'id'=>'partnerId')); ?>
        <?php echo CHtml::activeHiddenField($themeModel, 'type', array('value'=>'forum')); ?>
        
    <?php echo CHtml::endForm(); ?> 
</div>
</div>

</div>


<?php if(!empty($theme)) : ?>
    <div>
            <div class="forum_theme" style="margin-bottom: 30px;">
                
        <div style="display:none"><?php echo $theme['themeId'];?></div>
        <h2><?php echo $theme['title']; ?></h2>
        <div class="messageInfo" style="font-size:11px;margin-bottom:20px;">
            <?php if($theme['comDate'] + 86400 > time()) : ?>
                <span class="is_new_theme"></span>
            <?php endif; ?>
            <span class="date">
                <?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $theme['comDate']); ?>
            </span>&nbsp; 

            <a class="commentByName" href="#form">
                <span class="login">
                    <?php 
                    if(!empty($theme['user'])) {
                        echo $theme['user']['displayName'];
                    } else {
                        echo 'Гость';
                    } ?>
                </span>
            </a>&nbsp 
            <?php if(!empty($theme['user']['login'])) : ?>
                <span class="comment_numb">
                    <?php echo $theme['user']['forumComments'] + $theme['user']['reviews'] + $theme['user']['newsComments'] + $theme['user']['revComments'] + $theme['user']['blogComments']; ?>
                </span>  
            <?php endif; ?>
            <?php if($theme['isSupport']) : ?>
               &nbsp;&nbsp;<span class="support_q"></span> 
            <?php endif;?>

             <?php if($this->isForumModerator) : ?>
                <div class="pull-right moder_tools">
                    <?php if(!empty($theme['user']['role']) && $theme['user']['role'] == 'user') : ?>
                        <span class="banUser" style="color: red; cursor: pointer;">
                            <div style="display: none"><?php echo $item['userId']; ?></div>
                            Блокировать пользователя
                        </span> |
                    <?php endif; ?>
                    <?php if(empty($theme['user']['role']) || $theme['user']['role'] == 'user') : ?>
                        <span class="banByIp" title="Бан по IP" style="color: #000; cursor: pointer;"><?php echo $theme['userIp']; ?></span> |
                    <?php endif; ?>
                    <a style="color: red;" href="<?php echo Yii::app()->createUrl('partner/forum/editTheme', array('id'=>$theme['themeId'])); ?>">Править</a> |
                    <span class="delForumTh" style="color: red; cursor: pointer" data-id="<?php echo $theme['themeId']; ?>">Удалить</span>
                </div>
            <?php endif; ?>
        </div> 
        
        
        
        
       
        
        
        
        <div class="messageText">
                  <?php echo $theme['text']; ?>
        </div>
        
        
                <?php if(!empty($themeImg)) : ?>
                    <br/>
                    <?php foreach($themeImg as $item) : ?>
                        <a style="text-decoration:none;" href="#modal<?php echo $item['imgId']; ?>" class="big-link" data-toggle="modal" >
                            <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$item['smallImg']; ?>" style="width:40px;height:40px;" alt=""/>
                        </a> 
                        <div id="modal<?php echo $item['imgId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h3 id="myModalLabel">Фото</h3>
                            </div>
                            <div class="modal-body">
                                <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$item['bigImg']; ?>"/>
                            </div>
                        </div>
                     <?php endforeach; ?>
                     <br/> 
                <?php endif; ?>
                <br/>
                <span style="float: left; padding-right: 20px"> <a class="addComment bord" href="#form" data-id="<?php echo $theme['themeId']; ?>">Ответить</a> </span>
              <a class="qouteMessage bord" href="#form" data-id="<?php echo $theme['themeId']; ?>">Цитировать</a>
        
        
           </div>
        
               
        


<div class="forum_post_list" style="background:none;">

   
        <?php if(!empty($comments)) : ?>
            <?php foreach($comments as $com) : ?>
    
     <div class="forum_post">
                          <span id="<?php echo $com['comId']; ?>" style="position:absolute; top:-100px">&nbsp;</span>
                        <div class="post_header">
                            <div style="display:none"><?php echo $theme['themeId'];?></div>
                       
                            <a href="<?php echo '#'.$com['comId']; ?>" style="text-decoration:none;" class="comCounter"><?php echo '#'.$com['comId']; ?></a>
                            <span  class="date_forum_post">
                                <?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $com['comDate']); ?>
                            </span>&nbsp;
                            <?php if(!empty($com['user']['login'])) : ?>
                                <a class="commentByName" href="#form" data-id="<?php echo $theme['themeId'];?>">
                                    <span class="login">
                                        <?php echo !empty($com['user']['displayName']) ? $com['user']['displayName'] : $com['user']['login'] ; ?>
                                    </span>
                                </a>&nbsp; 
                                <span class="comment_numb">
                                    <?php echo $com['user']['forumComments'] + $com['user']['reviews'] + $com['user']['newsComments'] + $com['user']['revComments'] + $com['user']['blogComments']; ?>
                                </span> 
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a class="commentByName" href="#form" data-id="<?php echo $theme['themeId'];?>">
                                    <span class="login" style="display: none">
                                        <?php echo !empty($com['user']['displayName']) ? $com['user']['displayName'] : $com['user']['login'] ; ?>
                                    </span>
                                    Обратиться по нику
                                </a>
                            <?php else : ?>
                                <a class="commentGuestOnMain" href="#form" data-id="<?php echo $theme['themeId'];?>">
                                    <span class="login">
                                        Гость
                                    </span>
                                </a>&nbsp;
                            <?php endif; ?>
                                
                            <?php if($this->isForumModerator || $this->moderPost) : ?>
                                <span style="float: right">
                                    <div style="display: none;"> <?php echo $com['comId']; ?> </div> 
                                    <?php if($this->isForumModerator) : ?>
                                        <?php if(!empty($com['user']) && $com['user']['role'] == 'user') : ?>
                                            <span class="banUser" style="color: red; cursor: pointer;">
                                                <div style="display: none"><?php echo $com['user']['userid']; ?></div>
                                                Блокировать пользователя
                                            </span> |
                                        <?php endif; ?>
                                        <?php if(empty($com['user']) || $com['user']['role'] == 'user') : ?>
                                            <span class="banByIp" title="Бан по IP" style="color: red; cursor: pointer;"><?php echo $com['userIp']; ?></span> |
                                        <?php endif; ?>
                                    <?php endif; ?>       
                                    <a style="color: red;" href="<?php echo Yii::app()->createUrl('partner/forum/editComment', array('id'=>$com['comId'])); ?>">Править</a> |
                                    <span class="delForumCom" style="color: red; cursor: pointer">Удалить</span>
                                </span>
                            <?php endif; ?>
                            
                            <?php if(!empty($com['user']) && ($partner['delegate1'] == $com['user']['userid'] || $partner['delegate2'] == $com['user']['userid']) ) : ?>
                                &nbsp;&nbsp;<span class="support_q"></span> 
                            <?php endif; ?>
                                
                        </div>    
                                
                        <div class="post_message messageText">
                        <?php 
                            $str = $com['text'];
                            while(1) {
                                if(preg_match('/ \[quote(\s*|="(.*)")\s*(\s*|date="(.*)")\](.*)\[\/quote\](\s*|\S*)|\[quote /Uxis', $str)) {
                                    $str = CPartnerkiHelper::printQuotesAndMessage($str);
                                } else {
                                    echo $str;
                                    break;
                                }
                            }  ?>
                        </div>
                           <?php if(!empty($com['images'])) : ?>
                                <br/><br/>
                              <?php foreach($com['images'] as $comImg) : ?>
                                <a style="text-decoration:none;" href="#com-modal<?php echo $comImg['imgId']; ?>" class="big-link" data-toggle="modal" >
                                    <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['smallImg']; ?>"  alt=""/>
                                </a> 
                                <div id="com-modal<?php echo $comImg['imgId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                        <h3 id="myModalLabel">Фото</h3>
                                    </div>
                                    <div class="modal-body">
                                        <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['bigImg']; ?>"/>
                                    </div>
                                </div>
                              <?php endforeach; ?>
                          <?php endif; ?>
                            <br/>
                        </div>
            <?php endforeach; ?>
        <?php endif; ?>
    

    
 </div>
 </div>       
    
    <div class="pages"> <?php $this->widget('CLinkPager', array('pages' => $pagination)); ?> </div>
    
     <div  id="commentFileUpload">
        <div class="padding040">
            <div class="forum_form_cut form_cut_left"></div>
            <div class="comment_form">
                <?php echo CHtml::errorSummary($commentModel, 'Пожалуйста исправьте следующие ошибки:'); ?>    
                <?php echo CHtml::beginForm('', 'post', array('id'=>'form')); ?>
                    <div style="width:100%;display: inline-block;">
                        <span class="pull-right close_form"></span>
                    </div>
                    <div class="mar-top10 pull-left">
                        <?php echo CHtml::activeTextArea($commentModel, 'text', array('id'=>'editor','class'=>'text_area_comm','style'=>'width:600px;')); ?>
                    </div>
                    <div class="pull-left mar-top20">
                        <div id="commentFileUpload">
                            <?php $this->widget('xupload.XUpload', array(
                                'url' => Yii::app()->createUrl("partner/forum/upload"),
                                'model' => new XUploadForm, 
                                'attribute' => 'file',
                                'showForm' => false,    
                                'multiple' => true,
                                'options' => array( 
                                    'autoUpload' => true, 
                                    'maxNumberOfFiles' => 5, 
                                    'maxFileSize' => 500000,
                                    'acceptFileTypes' => "js:/(\.|\/)(jpg|png|gif)$/i",
                                ),
                                'downloadView'=>'downloadViewOrigin',
                                'htmlOptions' => array('id'=>'commentFileUpload'),
                            ));  ?>
                        </div>
                    </div>
                    <?php echo CHtml::activeHiddenField($commentModel, 'themeId', array('value'=>$theme['themeId'], 'id'=>'themeId')); ?>
                    <div class="pull-right mar-top5">
                        <?php if(Yii::app()->user->isGuest || (!Yii::app()->user->isGuest && !Yii::app()->user->getState('email')) ) : ?>
                            <div  class="subscrible_form_com pull-left ">
                                <?php echo CHtml::activeTextField($commentModel, 'subscrEmail', array('placeholder'=>'Подписаться на тему', 'class'=>'subscrible_input_com')); ?>
                            </div>
                        <?php else : ?>
                            <?php echo CHtml::activeCheckBox($commentModel, 'subscr',array('id'=>'ts1')); ?><label for="ts1">Подписаться на тему</label>
                        <?php endif; ?>
                    </div>
                    <div class="clearfix"></div>              
                    <div class="pull-left">
                        <?php echo CHtml::submitButton('Ответить', array('class'=>'addpst')); ?>
                    </div>
                <?php echo CHtml::endForm(); ?>
            </div>
        </div>
    </div>
    
    
    
    
    
    
    
<?php endif; ?> 
    
    

    
<div id="quotePointer">
    <div class="chat-bubble" >
        <a href="#form" class="quoteText">Цитировать</a>
        <div class="chat-bubble-arrow-border"></div>
        <div class="chat-bubble-arrow"></div>
    </div>
</div>    

    
      
<div class="modal hide fade" id="myModal">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Уведомление</h3>
  </div>
  <div class="modal-body">
    
  </div>
  <div class="modal-footer">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><a href="#" class="btn">Закрыть</a></button>
  </div>
</div>
    